import { defineStore } from "pinia";
import { computed, ref } from "vue";

export const useApiStore = defineStore(
  "api",
  () => {
    const aiapikey = ref("");
    const isApiKeyValid = computed(() => aiapikey.value.length > 0);
    
    function setApiKey(key) {
      aiapikey.value = key.trim();
    }
    
    function clearApiKey() {
      aiapikey.value = "";
    }
    
    return {
      aiapikey,
      isApiKeyValid,
      setApiKey,
      clearApiKey
    };
  },
  {
    persist: true
  }
);